//
//  MainViewController.h
//  chaohu
//
//  Created by 张键 on 2020/6/29.
//  Copyright © 2020 张键. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <IMSThingCapability/IMSThingCapability.h>

// NS_ASSUME_NONNULL_BEGIN

@interface JMIOTViewController : UIViewController

@property(nonatomic, copy) NSString *iotId;
@property(nonatomic, copy) NSString *token;
@property(nonatomic, copy) NSString *navTitle;
@property(nonatomic, copy) NSString *deviceId;
@property(nonatomic, copy) NSString *phoneNum;

@property(nonatomic, assign, readonly) bool isInterrupting;

@property(nonatomic, assign) bool isShowShareItem;

// 退出时是否销毁
@property(nonatomic, assign) bool shouldNotDestroyWhenExit;

@property(nonatomic, copy) void (^shareCallBack)(void);

@property(nonatomic, copy) void (^unbindCallBack)(NSString *iotId, NSDictionary *params);

#pragma mark - 飞燕设备模型

@property(weak, nonatomic) IMSThing *thingShell;

#pragma mark -

@property(strong, nonatomic) NSMutableDictionary *mdic_state;

#pragma mark - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- (void)InitUI;

#pragma mark -
- (IBAction)back:(id)sender;

#pragma mark - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#pragma mark - toast相关内容
- (bool)isShowToast:(UIButton *)btn;
#pragma mark - 按钮点击,可复用
- (IBAction)btnDown:(UIButton *)btn;
#pragma mark -更新按钮状态
- (void)updateBtnState:(UIButton *)btn;

#pragma mark - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#pragma mark - 初始化所有数据
- (void)resetALL;
#pragma mark - 销毁所有数据
- (void)destroyAll;

#pragma mark - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#pragma mark - 刷新所有状态
- (BOOL)isDataUpdated:(NSDictionary *)items completion:(void (^)(bool isEqual, NSDictionary *completionDic))block;
- (void)updateState:(NSDictionary *)items;

#pragma mark - IOT
- (void)destroyIOT;
- (void)configIOT;

#pragma mark - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#pragma mark -
- (void)getStatus;
- (void)getEvents;
- (void)getPropertiesFull;
- (void)getPropertiesFull:(void (^)(BOOL success, NSDictionary *items, NSError *responseError))block;
- (void)getPropertiesFull:(bool)isUpdate completionHandler:(void (^)(BOOL success, NSDictionary *items, NSError *responseError))block;
- (void)setProperties:(NSDictionary *)items completionHandler:(void (^)(BOOL success, id dataObject, NSError *responseError))block;
- (void)setProperties:(NSDictionary *)items getPropertiesFull:(void (^)(BOOL success, id dataObject, NSError *responseError))block;
- (void)setProperties:(NSDictionary *)items interrupt:(NSTimeInterval)duration completionHandler:(void (^)(BOOL success, id dataObject, NSError *responseError))block;

#pragma mark - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#pragma mark - IMSThingObserver

/**
 物的状态变更回调，如上线，离线等
 @param iotId 物的 iotId
 @param params 描述具体状态
 */
- (void)onStatusChange:(NSString *)iotId params:(NSDictionary *)params;

/**
 物有事件触发，如提示，告警等

 @param iotId 物的 iotId
 @param params 描述具体事件
 */
- (void)onEventHappen:(NSString *)iotId params:(NSDictionary *)params;

#pragma mark - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#pragma mark -

- (void)startTimer;
- (void)destroyTimer;

@end

// NS_ASSUME_NONNULL_END
